<template>
   <div class="app-container">
      <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">
         <el-form-item label="公告标题" prop="noticeTitle">
            <el-input
               v-model="queryParams.noticeTitle"
               placeholder="请输入公告标题"
               clearable
               style="width: 200px"
               @keyup.enter="handleQuery"
            />
         </el-form-item>
  
         <el-form-item label="类型" prop="noticeType">
            <el-select v-model="queryParams.noticeType" placeholder="公告类型" clearable style="width: 200px">
               <el-option
                  v-for="dict in sys_notice_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
               />
            </el-select>
         </el-form-item>
         <el-form-item>
            <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
         </el-form-item>
      </el-form>

      <el-table v-loading="loading" :data="noticeList" @selection-change="handleSelectionChange">
     
             <el-table-column type=index min-width='20' label="序号" >
          <template  #default="scope">
            <span>{{(queryParams.pageNum- 1) * queryParams.pageSize + scope.$index + 1}}</span>
          </template>
 </el-table-column>
         <el-table-column
            label="公告标题"
            align="center"
            prop="noticeTitle"
            :show-overflow-tooltip="true"
         />
         <el-table-column label="公告类型" align="center" prop="noticeType" width="100">
            <template #default="scope">
               <dict-tag :options="sys_notice_type" :value="scope.row.noticeType" />
            </template>
         </el-table-column>
         <el-table-column label="状态" align="center" prop="status" width="100">
            <template #default="scope">
               <dict-tag :options="sys_notice_status" :value="scope.row.status" />
            </template>
         </el-table-column>
         <el-table-column label="创建者" align="center" prop="createBy" width="100" />
         <el-table-column label="发布时间" align="center" prop="createTime" width="100">
            <template #default="scope">
               <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
            </template>
         </el-table-column>
         <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template #default="scope">
               <el-button link type="primary" icon="View" @click="handleUpdate(scope.row)" >查看</el-button>
            </template>
         </el-table-column>
      </el-table>

      <pagination
         v-show="total > 0"
         :total="total"
         v-model:page="queryParams.pageNum"
         v-model:limit="queryParams.pageSize"
         @pagination="getList"
      />

      <!-- 添加或修改公告对话框 -->
      <!-- 添加或修改公告对话框 -->
      <el-dialog  v-model="open" width="60%" append-to-body>
      
<div class="no-breadNav-padd">
        <div class="article oneColumn">
            <h1 id="ti">
                  {{form.noticeTitle}}
            </h1>
            <div class="pages-date">
                发布时间:{{form.createTime}}
            </div>
            <div class="pages_content" id="UCAP-CONTENT">
                <div class="trs_editor_view TRS_UEDITOR trs_paper_default trs_web">
                   <p v-html="form.noticeContent"></p> 
                  </div>
            </div>
        </div>
    </div>
    
      </el-dialog>
   </div>
</template>

<script setup name="Notice">

import * as homeApi  from "@/api/home/index";

const { proxy } = getCurrentInstance();
const { sys_notice_status, sys_notice_type } = proxy.useDict("sys_notice_status", "sys_notice_type");

const noticeList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    noticeTitle: undefined,
    isAsc: undefined,
    orderByValue: "desc",
    orderByColumn: "createTime",
  },
  rules: {
    noticeTitle: [{ required: true, message: "公告标题不能为空", trigger: "blur" }],
    noticeType: [{ required: true, message: "公告类型不能为空", trigger: "change" }]
  },
});

const { queryParams, form, rules } = toRefs(data);

/** 查询公告列表 */
function getList() {
  loading.value = true;
  homeApi.getNoticeList(queryParams.value).then(response => {
     
    
    noticeList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  }
) .catch(err=>{loading.value = false;})
 }

/** 取消按钮 */
function cancel() {
  open.value = false;
  reset();
}

/** 表单重置 */
function reset() {
  form.value = {
    noticeId: undefined,
    noticeTitle: undefined,
    noticeType: undefined,
    noticeContent: undefined,
    status: "0"
  };
  proxy.resetForm("noticeRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

/** 多选框选中数据 */
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.noticeId);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加公告";
}

/**修改按钮操作 */
function handleUpdate(row) {
  reset();
 form.value = row;
    open.value = true;
    title.value = "公告详情";
}
getList();
</script>


<style scoped lang="scss">
@import url("../index.scss");
.no-breadNav-padd {
    padding-top: 26px;
}
.oneColumn {
 
    padding: 0px 30px 30px 30px;
    margin: 0 auto;
}
.title1 {
    font-size: 24px;
    text-align: center;
    line-height: 56px;
    padding-top: 15px;
}
h1 {
    line-height: 56px;
    font-family: "微软雅黑", "宋体";
    font-size: 30px;
    text-align: center;
    padding: 0 0 26px;
    font-weight: normal;
}
.pages-date {
    position: relative;
    height: 35px;
    border-bottom: 1px #dcdcdc solid;
    padding-top: 7px;
    text-align: left;
}
.pages_content {
    line-height: 30px;
    margin: 0;
    padding: 20px 0 20px 0;
    font-size: 16px;
}
</style>
